<?php
/**
 * @Author: xuzhiyi
 * @Date:   2016-02-22 23:59:48
 * @Last Modified by:   xuzhiyi
 * @Last Modified time: 2016-02-27 11:47:52
 * ------------------------------------------------ *
 * 品牌管理                                         *
 * ------------------------------------------------ */

namespace Admin\Controller;
class BrandsController extends CommonController {

public function index(){
		if(IS_AJAX){
			switch(I('ajax')){				
				case "delBrands":
					$status = D('Brands')->delBrands();
					$this->ajaxReturn($status);
					break;
				default:
			 		$result = M('Brands')->where('brandFlag=1')->select();
			 		$output['data'] = $result;
			 		$this->ajaxReturn($output);
			}
		}

		if(I('noAjax')=="editBrands"){
			
			if((int)I('brandId',0)>0){
				$m = D('Brands')->editBrands();
				if($m){	
									
					echo "<script>parent.callback('品牌修改成功！',1)</script>";
					return;
				}		
				echo "<script>parent.callback('品牌修改失败！',0)</script>";
				return;
			}
			$m = D('Brands')->addBrands();

			if($m){	
				//echo "<script>parent.callback('".$m."',0)</script>";				
				echo "<script>parent.callback('品牌添加成功！',1)</script>";
				return;
			}		
			echo "<script>parent.callback('品牌添加失败！',0)</script>";
			return;

		}
		$this->display();
	}


	public function edit(){
		$catName1 = M('goods_cats')->where("catFlag=1 and parentId=0")->field('catId,catName')->select();
		if((int)I('brandId',0)>0){
			$brands = M('brands')->where('brandId='.(int)I('brandId'))->find();
			$catIds=M('goods_cat_brands')->where('brandId='.(int)I('brandId'))->getField('catId',true);
			$this->assign('brands',$brands);
			$this->assign('catIds',$catIds);			
		}
		$this->assign('catName1',$catName1);
		$this->display();
	}
}